package 单例模式;

//恶汉模式
public class SingleMode {
    public static SingleMode instance=new SingleMode();
    private SingleMode() {
        ;
    }
    public static SingleMode getInstance(){
        return instance;
    }
}

//懒汉模式
class SingleLazy{
    public static volatile SingleLazy instance=null;
    private SingleLazy() {
        ;
    }
    public static SingleLazy getInstance() {
        if (instance == null) {
            synchronized (SingleLazy.class) {
                if (instance == null) {
                    //创建一个对象
                    instance = new SingleLazy();
                }

            }
        }
        return instance;
    }
}

